<!DOCTYPE html>
<html>
<head>
<title>req_new</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
<script type="text/javascript" src="/codebase/dhtmlx.js" />

<script>
/*<![CDATA[*/
	var myForm, myForm2,myEditor_test_guide,myEditor_req_remark;
	var customCss = {
		video_bitrate : "validate_magenta",
		video_codec : "validate_orange"
	};
	function doOnLoad() {
		var v=document.getElementById("assign_req_id").innerHTML;
		
		myEditor_test_guide = new dhtmlXEditor("editorObj");
		myEditor_req_remark = new dhtmlXEditor("editorObj2");
		
		
		formStructure=null;
		formStructure=[
						{type:'fieldset',label:'附件',list:[
									{type : 'label', name:'att_label', label:'上传文件最大值: 100 Mb'},
									{type:'upload', name:'myFiles', inputWidth:'600', titleText:'拖拽文件到此区域或点击选择文件上传', url:'/attachment/new_test_upload', _swfLogs:'enabled',  autoStart:'true', swfPath:'/common/uploader.swf',  swfUrl:'/attachment/new_test_upload'}
						]},	
		                 
							{type:'block',list:[
									{type : 'button',name : 'test_new_save_btn',value : '送测'}															
								]
		                  	}	
		                 ];
		

		
      
        
		//form_container
		if (myForm2) {
			myForm2.unload();
			myForm2 = null;

		}
		myForm2 = new dhtmlXForm("form_container2",formStructure);
		//  myForm = new dhtmlXForm("myForm", formData);
		
		//form_container
		if (myForm) {
			myForm.unload();
			myForm = null;

		}
		myForm = new dhtmlXForm("form_container");
		//myForm.loadStruct("/common/testmanager/test_new.xml");
		myForm.loadStruct("/test/test_new_form_onload?req_id="+v);
		                                      			
		myForm.attachEvent("onValidateError", function (name, value, result){
			var tmp_label=myForm.getItemLabel(name);	
		
		    alert("校验【"+tmp_label+"】 值为【"+value+ "】 ， 请更正");
		});
		
		myForm.attachEvent("onButtonClick", function(name) {					
			if(name=="select_req_btn"){
				createWindow();
				
			}
					
		});
		
		myForm.attachEvent("onChange", function(name, value){			
			  if(name=='req_title'){					  
				 document.getElementById("assign_req_id").innerHTML=value;
				 doOnLoad();
				  //myForm.loadStruct("/test/test_new_form_onload?req_id="+value);									 				
			  }
	  
		}); 
		 
		myForm2.attachEvent("onButtonClick", function(name) {
			
				if (name == "test_new_save_btn") {
					var tmp_test_guide=myEditor_test_guide.getContent();
					if(tmp_test_guide.length>0){
						//tmp_test_guide=removeHTMLTag(tmp_test_guide);
						myForm.setItemValue("test_guide", tmp_test_guide);
						
						var tmp_req_remark=myEditor_req_remark.getContent();
						
						//tmp_req_remark=removeHTMLTag(tmp_req_remark);
						myForm.setItemValue("req_remark", tmp_req_remark);						
						myForm.send("/test/test_new_save", "post", callback);
					}else{
						alert("【测试指引】 字段为必填项，请录入");
					}
				}
										
			});
		 
			myForm2.attachEvent("onUploadFile", function(realName, serverName) {
				atts_add_gropid(arguments[2].att_gropid);
				atts_add_ids(arguments[2].att_ids);
				//var mu=myForm.getUploader("myFiles");
			});
			
			myForm2.attachEvent("onUploadComplete",function(count){
				//logEvent("<br></br>onUploadComplete "+count+" file"+(count>1?"s were":" was")+" uploaded");
				alert("上传"+count+"个文件完成.");
			});
			
			myForm2.attachEvent("onUploadFail",function(realName){
				//logEvent("onUploadFail, file: "+realName);
				alert("上传文件"+realName+"失败，请检查上传文件大小");
			});
			
	}

	function removeHTMLTag(str) {
        str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
        str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
        str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
        str=str.replace(/ /ig,'');//去掉 
        return str;
}
			
	function createWindow() {
		//alert("open_createWindow");
		var p = 0;		
		var id = "select_req_window";
		//
		var w = 900;
		var h = 600;
		var x = 10;
		var y = 10;
		
		//
		dhxWins=new dhtmlXWindows();
		dhxWins.createWindow(id, x, y, w, h);
		dhxWins.window(id).setText("项目选择界面");
		
		dhxWins.window(id).denyPark();
		dhxWins.window(id).button("park").hide();
		
		dhxWins.window(id).attachURL("/test/test_new_select_req");
		/* dhxWins.attachEvent("onClose", function(win){
			    var ifr = dhxWins.window(id).getFrame();
			    var win_value = ifr.contentWindow.document.getElementById("assign_req_id").innerHTML;
			    //alert("win_value "+win_value);
			    window.location.pathname="/test/test_new?req_id="+win_value;
			    return true;
			    
			}); */
		dhxWins.attachEvent("onClose", function(win){
		    
		    var ifr = dhxWins.window(id).getFrame();
		    var win_value = ifr.contentWindow.document.getElementById("select_req_id").innerHTML;
		    
		    document.getElementById("assign_req_id").innerHTML=win_value;
		    //alert("win_value "+win_value);
		    //window.location.pathname="/test/test_assign?req_id="+win_value;
		    doOnLoad();
		 // alert("onClose");
		    return true;
		    
		});
	
	}
	
	var callback=function () {
		//alert("callback");
		
		if(arguments[1]=="true"){
			alert("保存信息成功");	
			myForm.clear();
			myEditor_test_guide.setContent("");
			myEditor_req_remark.setContent("");						
			var myUploader = myForm2.getUploader("myFiles");
			myUploader.clear();
			//window.location.assign("/test/test_new");
		}
		else{
			alert("保存信息，错误信息："+arguments[1]);
		}
	}
	
	function atts_add_ids(ids) {
		var txt="";
		//var get_input_att_ids=myForm.getInput("att_id");
		//txt=get_input_att_ids.value;
		txt=myForm.getItemValue("att_id");
		if (txt==""){
			//get_input_att_ids.value=ids;
			myForm.setItemValue("att_id",ids);
		}else{
			//get_input_att_group.value=txt+","+ids;
			myForm.setItemValue("att_id",txt+","+ids);
		}				
		//att_group.hide=true;
		//atts.hidden=true;
	}
	
	function atts_add_gropid(g_id) {
		var txt="";
		//var get_input_att_group=myForm.getInput("att_group_id");
		//txt=get_input_att_group.value;
		txt=myForm.getItemValue("att_group_id");
		if (txt==""){
			//get_input_att_group.value=g_id;
			myForm.setItemValue("att_group_id",g_id);
		}else{
			//get_input_att_group.value=txt+","+g_id;
			myForm.setItemValue("att_group_id",txt+","+g_id);
		}				
		//att_group.hidden=true;
		//atts.hide=true;
	}
	/*]]>*/	
</script>
</head>
<body onload="doOnLoad();">
<div id="assign_req_id" name="assign_req_id" th:text="${req_id}" style="display: none;" > </div>
	<table style="padding-left: 50px;">
		<tr>
			<td>
				<div id="form_container" name="form_container" ></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="">测试指引<label style="color:red;">*</label></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="editorObj"  style="width:700px; height:200px; border:1px solid #dfdfdf;"></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="">其他说明</div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="editorObj2" style="width:700px; height:200px;  border:1px solid #dfdfdf;"></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="form_container2" name="form_container2"
					 ></div>
			</td>
		</tr>
	</table>
	   
</body>
</html>